package com.hpe.websocket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;

/**
 * Created by tiansha on 2015/11/12.
 */
@Controller
public class GreetingController {

    @Autowired
    private SimpMessagingTemplate messagingTemplate;

    @MessageMapping("/hello")
    @SendTo("/topic/greetings")
    //@SendToUser("/queue/position-updates")
    public Greeting greeting(HelloMessage message) throws Exception {
        //Thread.sleep(3000); // simulated delay
        //messagingTemplate.convertAndSendToUser("testuser", "/message", new Greeting("User Hello, " + message.getName() + "!")); // send to specific user
        //messagingTemplate.convertAndSend("/topic/greetings", greeting); // broadcast
        return new Greeting("Hello, " + message.getName() + "!");
    }

}
